package org.alvin.code.jdbc.aop;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.Statement;

@Slf4j
public class StatementProxyHandler implements InvocationHandler {
    private final Statement target;

    public StatementProxyHandler(Statement target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("execute") || method.getName().equals("executeQuery") || method.getName().equals("executeUpdate")) {
            String sql = (String) args[0];
            log.info("Executing SQL:{} " + sql);
        }
        return method.invoke(target, args);
    }
}